package ynu.edu.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import ynu.edu.po.DeliveryAddress;
import ynu.edu.service.IDeliveryAddressService;

import java.util.List;

@RestController
@RequestMapping("deliveryAddress")
@Tag(name = "送货地址服务")
public class DeliveryAddressController {
    @Resource
    private IDeliveryAddressService deliveryAddressService;

    @PostMapping("/listDeliveryAddressByUserId")
    @Operation(summary = "查询送货地址",
            description = "根据用户编号查询所属送货地址")
    @Parameter(name = "userId", description = "用户编号")
    public List<DeliveryAddress> listDeliveryAddressByUserId(@RequestParam String userId) {
        return deliveryAddressService.listDeliveryAddressByUserId(userId);
    }

    @PostMapping("/getDeliveryAddressById")
    @Operation(summary = "查询送货地址",
            description = "根据送货地址编号查询送货地址")
    @Parameter(name = "daId", description = "送货地址编号")
    public DeliveryAddress getDeliveryAddressById(@RequestParam Integer daId) {
        return deliveryAddressService.getDeliveryAddressById(daId);
    }

    @PostMapping("/saveDeliveryAddress")
    @Operation(summary = "更新送货地址",
            description = "根据送货地址编号更新送货地址信息。" +
                    "需要deliveryAddress送货地址JSON实体，" +
                    "实体需包含contactName、contactSex、contactTel、address、userId参数")
    public boolean saveDeliveryAddress(@RequestBody DeliveryAddress deliveryAddress) {
        return deliveryAddressService.saveDeliveryAddress(deliveryAddress);
    }

    @PostMapping("/updateDeliveryAddress")
    @Operation(summary = "更新送货地址",
            description = "根据送货地址编号更新送货地址信息。" +
                    "需要deliveryAddress送货地址JSON实体，" +
                    "实体需包含daId、contactName、contactSex、contactTel、address、userId参数")
    public boolean updateDeliveryAddress(@RequestBody DeliveryAddress deliveryAddress) {
        return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
    }

    @PostMapping("/removeDeliveryAddress")
    @Operation(summary = "删除送货地址",
            description = "根据送货地址编号删除一条记录")
    @Parameter(name = "daId", description = "送货地址编号")
    public boolean removeDeliveryAddress(@RequestParam Integer daId) {
        return deliveryAddressService.removeDeliveryAddress(daId);
    }
}
